﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using SaleWebsite.library;
using System.Web.Mvc;


namespace SaleWebsite.Models
{
    public class Product_Type
    {
        public ulong Id { get; set; }
        public string Name { get; set; }
        public ulong Group_Id { get; set; }
        public string Group_name{get;set;}
        public Product_Type(ulong id,string name,ulong group_id)
        {

            this.Id = id;
            this.Name = name;
            this.Group_Id=group_id;
        }
        public Product_Type()
        {

        }
        public ulong Insert()
        {
            
           try
           {
               return MySqlImplement.GetInstance().ExcuteQuery(Params.GetAllParams(this), "product_type_insert");
           }
           catch (System.Exception ex)
           {
           	throw ex;
           }
           
        }
        public static DataSet GetAll()
        {
            return MySqlImplement.GetInstance().GetQuery("product_type_getall");
        }
        
        
        public  int Delete()
        {
            return MySqlImplement.GetInstance().ExcuteCommand(Params.GetAllParams(this),"product_type_delete");
        }
        public int Save()
        {
          try
          {
              return MySqlImplement.GetInstance().ExcuteCommand(Params.GetAllParams(this), "product_type_update");
          }
          catch (System.Exception ex)
          {
          	throw ex;
          }
        }
        private static SelectListItem GetOneSelect(DataRow row, ulong id)
        {
            return new SelectListItem()
            {

                Value = row["product_id"].ToString(),
                Text = row["product_name"].ToString(),
                Selected = ulong.Parse(row["product_id"].ToString()) == id ? true : false

            };
        }
        public static IEnumerable<SelectListItem> GetAllSelect(ulong id)
        {
            foreach (DataRow row in GetAll().Tables[0].Rows)
            {
                yield return GetOneSelect(row, id);
            }
        }
    }
}